package com.mike.server.support;

import java.util.concurrent.ConcurrentLinkedQueue;

import org.apache.log4j.Logger;

import com.mike.server.engine.IGameMessage;

public abstract class BaseService implements IService, Runnable {

	private static final Logger LOG = Logger.getLogger(BaseService.class);
	
	protected ConcurrentLinkedQueue<IGameMessage> gameMessages = new ConcurrentLinkedQueue<IGameMessage>();
	
	public void addMesage(IGameMessage gameMessage) {
		if(null != gameMessage) {
			gameMessages.add(gameMessage);
		}
	}
	
	@Override
	public void shurdown() {
		LOG.info("shurdown");
	}

	@Override
	public void init() {
		LOG.info("start");

	}

	@Override
	public void stop() {
		LOG.info("stop");
	}

	/** 逻辑处理 */
	protected abstract void onReceive(IGameMessage gameMesage);
	
	@Override
	public void run() {
		if(null != gameMessages) {
			IGameMessage poll = gameMessages.poll();
			if(null != poll){
				onReceive(poll);
			}
		}
	}
	
	
}
